package com.kabao.javafx.imgdemo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;


public class ImageApp extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        BorderPane root = new BorderPane();

        String url = "https://c-ssl.duitang.com/uploads/blog/202306/17/lGSjy1Ldcx0JLwa.jpg";
        //完全记载
//        ImageView iv = new ImageView(url);
        //设置一个请求的高度大小
        ImageView iv = new ImageView(new Image(url,100,100,true,true, true));
        root.setCenter(iv);
        Button btn = new Button("设置图片");
        btn.setOnAction(event -> {
            Image image = new Image(getClass().getResourceAsStream("/img/cloud.png"));
            iv.setImage(image);
        });
        root.setBottom(btn);

        primaryStage.setScene(new Scene(root,520,380));
        primaryStage.setTitle("Fx image App");
        primaryStage.getIcons().add(
                new Image(getClass().getResource("/img/cloud.png").toExternalForm())
        );
        primaryStage.show();
    }
}
